<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>收银日报</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<style>
		.layui-input{width:150px;}
		.layui-form-label{width:auto;}
		.layui-form-item .layui-input-inline{width: 150px;}
		.inputdiv{display:flex;height: 38px;line-height: 38px;}
		.inputdiv i{position:absolute;right:10px;}
		.layui-table-cell .layui-table-link {color: #ff6a08!important;}}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="" id="searchform">
					<div class="layui-form-item">
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline" id="date-range">
							<label class="layui-form-label">日期范围</label>
							<div class="layui-input-inline">
					          <input type="text" name="start" value="" autocomplete="off" id="start-date" class="layui-input" placeholder="开始日期">
					        </div>
					        <div class="layui-form-mid">-</div>
					        <div class="layui-input-inline">
					          <input type="text" name="end" value="{php}echo date('Y-m-d');{/php}" autocomplete="off" id="end-date" class="layui-input" placeholder="结束日期">
					        </div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">快速设置</label>
							<div class="layui-input-inline">
								<select lay-filter="getdate">
									<option value="0">全部</option>
									<option value="1">今天</option>
									<option value="2">昨天</option>
									<option value="3">本周</option>
									<option value="4">上周</option>
									<option value="5">本月</option>
									<option value="6">上月</option>
									<option value="7">本季</option>
									<option value="8">上季</option>
									<option value="9">今年</option>
								</select>
							</div>
						</div>
						
					</div>
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline">
								<label class="layui-form-label">分店仓库</label>
								<div class="layui-input-inline inputdiv">
									<input type="text" name="branch_no" id="branch_no" autocomplete="off" value="" placeholder="" class="layui-input" onfocus="showBranchs()">
									<i class="layui-icon layui-icon-home"></i>
								</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">营业员号</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="oper_id" id="operator" placeholder=""  autocomplete="off" class="layui-input" onfocus="showOperators()">
								<i class="layui-icon layui-icon-username"></i>
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="day-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
							<a class="pear-btn pear-btn-warming pear-btn-md" onclick="exportxls()">
							<i class="pear-icon pear-icon-chart-bar"></i>
							导出报表
							</a>
						</div>
					</div>
					
					</div>
					
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body" id="day-body1">
				<table id="recon1-table" lay-filter="recon1-table"></table>
			</div>
			
			<div class="layui-card-body" id="day-body2" style="display:none;">
				<table id="recon2-table" lay-filter="recon2-table" ></table>
			</div>
		</div>
		<script type="text/html" id="rmbTpl">
			{{#  if(d.pay_rmb_amt!==undefined){ }}
    			<span style="color: #008000;">{{ d.pay_rmb_amt}}</span>
  			{{#  } }}
		</script>
		<script type="text/html" id="crdTpl">
			{{#  if(d.pay_crd_amt!==undefined){ }}
    			<span style="color: #008000;">{{ d.pay_crd_amt }}</span>
  			{{#  } }}
		</script>
		<script type="text/html" id="cardTpl">
			{{#  if(d.pay_card_amt!==undefined){ }}
    			<span style="color: #008000;">{{ d.pay_card_amt }}</span>
  			{{#  } }}
		</script>
		<script type="text/html" id="chaTpl">
			{{#  if(d.pay_cha_amt!==undefined){ }}
    			<span style="color: #008000;">{{ d.pay_cha_amt }}</span>
  			{{#  } }}
		</script>
		<script type="text/html" id="zfbTpl">
			{{#  if(d.pay_zfb_amt!==undefined){ }}
    			<span style="color: #008000;">{{ d.pay_zfb_amt }}</span>
  			{{#  } }}
		</script>
		<script type="text/html" id="wxTpl">
			{{#  if(d.pay_wx_amt!==undefined){ }}
    			<span style="color: #008000;">{{ d.pay_wx_amt}}</span>
  			{{#  } }}
		</script>
		<script type="text/html" id="sumTpl">
			{{#  if(d.pay_sum_amt!==undefined){ }}
    			<span style="color: #008000;">{{ d.pay_sum_amt}}</span>
  			{{#  } }}
		</script>
		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script src="__STATIC__/js/admin/common.js"></script>
		<script>
			var branch_no="";
			var _layerIndex=null;
			var operator_url="{:U('Controls/operators')}";
			var branchs_url="{:U('Controls/branchs')}";
			
			layui.use(['table', 'form', 'jquery','common','laydate','treetable'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;
				let laydate = layui.laydate;
				let treetable = layui.treetable;
				
			  	laydate.render({
					    elem: '#date-range'
					    ,range: ['#start-date', '#end-date']
			    });

				let DATA_PATH = "/{$MODULE_NAME}/pos/payflow/";
				
				//收银员对账 列
				let cols1 = [
					[
						{
							title: '序号',
							field: 'rowIndex',
							align: 'left',
							width: 80
						},
						{
							title: '门店编号',
							field: 'branch_no',
							align: 'left',
							totalRowText: '门店总计',
							width: 150
						},
						{
							title: '门店名称',
							field: 'branch_name',
							align: 'left',
							width: 150
						},
						{
							title: 'POS编码',
							field: 'pos_id',
							align: 'left',
							width: 100
						},
						{
							title: '收银员编码',
							field: 'oper_id',
							align: 'left',
							width: 120
						},
						{
							title: '收银员姓名',
							field: 'oper_name',
							align: 'left',
							width: 100
						},
						{
							title: '人民币现金',
							field: 'pay_rmb_amt',
							align: 'left',
							templet: '#rmbTpl',
							totalRow: true,
							width: 120
						},
						{
							title: '信用卡',
							field: 'pay_crd_amt',
							align: 'left',
							templet: '#crdTpl',
							totalRow: true,
							width: 120
						},
						{
							title: '预付费卡',
							field: 'pay_card_amt',
							align: 'right',
							totalRow: true,
							templet: '#cardTpl',
							width: 120
						},
						{
							title: '余额支付',
							field: 'pay_cha_amt',
							align: 'right',
							totalRow: true,
							templet: '#chaTpl',
							width: 100
						},
						{
							title: '支付宝',
							field: 'pay_zfb_amt',
							align: 'right',
							totalRow: true,
							templet: '#zfbTpl',
							width: 100
						},
						{
							title: '微信',
							field: 'pay_wx_amt',
							align: 'right',
							totalRow: true,
							templet: '#wxTpl',
							width: 100
						},
						{
							title: '合计',
							field: 'pay_sum_amt',
							align: 'right',
							totalRow: true,
							templet: '#sumTpl',
							width: 100
						},
						{
							title: '合计[折合人民币]',
							field: 'pay_sum_amt',
							align: 'right',
							totalRow: true,
							templet: '#sumTpl',
							width: 100
						}
					]
				]
				;
				
				
				
				window.render = function(_where={}){
					treetable.render({
		                treeColIndex: 1,
		                treeSpid: 0,
		                treeIdName: 'powerId',
		                treePidName: 'parentId',
		                skin:'line',
		                method:'post',
		                where:_where,
		                treeDefaultClose: false,
		                elem: '#recon1-table',
		                url: DATA_PATH+"dayreportData",
		                page: false,
		                cols: cols1
		            });
		        }
				
				render($('#searchform').serialize());

				form.on('select(getdate)', function(data) {
					date = new Array(2);
					var selc=parseInt(data.value);
		            switch (selc)
		            {
		            	case 1://当前天
	                    	date[0] = '{php}echo date('Y-m-d');{/php}';
	                    	date[1] = '{php}echo date('Y-m-d');{/php}';
	                    break;
		                case 2://昨天
		                    date[0] = '{php}echo date('Y-m-d', strtotime('-1 day'));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', strtotime('-1 day'));{/php}';
		                    break;
		                case 3://本周
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));{/php}';
		                    break;
		                case 4://上周
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));{/php}';
		                    break;
		                case 5://本月
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m"),1,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,date("m"),date("t"),date("Y")));{/php}';
		                    break;
		                case 6://上月
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m")-1,1,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d',mktime(23,59,59,date("m") ,0,date("Y")));{/php}';
		                    break;
		                case 7://本季度
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0,0,ceil((date('n'))/3)*3-3+1,1,date('Y')));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,ceil((date('n'))/3)*3,date('t',mktime(0, 0 ,0,ceil((date('n'))/3)*3,1,date("Y"))),date('Y')));{/php}';
		                    break;
		                case 8://上季度
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0,0,(ceil((date('n'))/3)-1)*3-3+1,1,date('Y')));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,(ceil((date('n'))/3)-1)*3,date('t',mktime(0, 0 ,0,(ceil((date('n'))/3)-1)*3,1,date("Y"))),date('Y')));{/php}';
		                    break;
		                case 9://本年
		                    date[0] = '{php}echo date('Y-01-01');{/php}';
		                    date[1] = '{php}echo date('Y-12-31');{/php}';
		                    break;
		            }
		            $('#start-date').val( date[0]);
	                $('#end-date').val(date[1]);
				});
				
				form.on('submit(day-query)', function(data) {
					render(data.field);
					return false;
				});
				
				//显示分店选择框
				window.showBranchs=function(){
					_layerIndex=openWin("分店仓库选择",branchs_url,"800px","600px");
				}
				
				//门店选择后的回调函数
				window.callBackBranch=function(data){
					
					var arr=new Array();
					for(var i in data){
						arr.push(data[i]['branch_no']);
					}
					
					$("#branch_no").val(arr.join(","));
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
					_layerIndex=null;
				}
				
				//显示操作员选择框
				window.showOperators=function(){
					var oval=$("#operator").val();
					
					if(_layerIndex==null||oval==''){
						_layerIndex=openWin("营业员选择",operator_url,"800px","600px");
					}
				}
				
				//操作员选择后的回调函数
				window.callBackOprator=function(data){
					
					$("#operator").val(data[0]['oper_id']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
						_layerIndex=null;
					}
				}

				//导出报表
				window.exportxls=function(){
					var param=$('#searchform').serialize();
					window.location.href="/{$MODULE_NAME}/pos/payflow/exportday?"+param;
				}
				
				window.refresh = function(param) {
					table.reload('day-table');
				}
			})
		</script>
	</body>
</html>
